
function setTost(state, text, type) {
  state.toast.type = type
  state.toast.text = text
  state.toast.action = new Date().getTime()
}

const vux = {
  state: {
    toast: {
      action: null,
      text: '',
      type: 'text'
    },
    /**
     * 加载指示
     */
    loading: {
      show: false,
      text: ''
    }
  },
  mutations: {
    /**
     * toast 显示成功
     */
    VUX_SHOW_TOAST_SUCCESS (state, text) {
      setTost(state, text, 'success')
    },
    /**
     * toast 显示警告
     */
    VUX_SHOW_TOAST_INFO (state, text) {
      setTost(state, text, 'warn')
    },
    /**
     * toast 显示失败
     */
    VUX_SHOW_TOAST_ERROR (state, text) {
      setTost(state, text, 'cancel')
    },
    /**
     * toast 显示文字
     */
    VUX_SHOW_TOAST_TEXT (state, text) {
      setTost(state, text, 'text')
    },
    /**
     * 更新加载状态
     * @param state
     * @param payload
     */
    VUX_LOADING (state, show, text = '') {
      state.loading.show = show
      state.loading.text = text
    }
  },
  actions: {
  }
}

export default vux
